<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="t"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<c:url var="godMode" value="/godMode" />

<style>
.table_add_url{width:90%;margin:30px;padding:30px;background:#fff;border:1px solid;}
.table_add_url tr th{border:1px solid;font:bold;}
.table_add_url tr td{border:1px solid; padding:0px 3px 0px 0px;}
.table_add_url tr td input{width:100%; }
.table_add_url tr td select{width:100%;}
/* .table_add_url tr td input{width:97%; margin:0px 2px 0px 2px;} */
/* .table_add_url tr td select{width:97%;margin:0px 2px 0px 2px;} */

.table_add_url .table_name{width:10%;}
.table_add_url .table_attr{width:10%;}
.table_add_url .table_url{}
.table_add_url .table_action{width:20%;}


</style>

<script type="text/javascript">

function logs(s){
	if(typeof console == 'object'){
		console.log(s);
	}
}

$(document).ready(function() {
	logs("is come???");
// 	$(':button').unbind('click', register);
// 	$(':button').bind('click', register);

// 	$('#attr1').change(changeAttr2);

});




function modify(obj){
	var tr = $(obj).parent().parent();
	
	var isSuccess = false;
	
	var param ='';
	$.each($(tr).children(), function(){
		var id = $(this).children().attr('id');
		
		if(typeof id == 'undefined'){
			return true;	// continue
		}
		
		var val = $(this).children().val();
		if(param.length==0){
			param=id+'='+val;	
		}else{
			param+='&'+id+'='+val;
		}
		$('form :input [name='+id+']').val(val);
		isSuccess = true;
	});
// 	logs(param);
	
	if(isSuccess){
		$('form').attr('action', '${godMode }'+'/modify').submit();
	}
	
	
}


function insert(obj){
	
	var tr = $(obj).parent().parent();
	var isSuccess = false;
	
	var param ='';
	$.each($(tr).children(), function(){
		var id = $(this).children().attr('id');
		
		if(typeof id == 'undefined'){
			return true;	// continue
		}
		
		var val = $(this).children().val();
		
		if(val.length==0){
			isSuccess = false;
			alert('항목이 누락되었습니다.');
			return false;
		}
		
		if(param.length==0){
			param=id+'='+val;	
		}else{
			param+='&'+id+'='+val;
		}
		$('form [name='+id+']').val(val);
		logs($('form [name='+id+']').val());
		isSuccess = true;
	});
// 	logs(param);
	if(isSuccess){
		$('form').attr('action', '${godMode }'+'/insert').submit();
	}
	
}
	
// 	logs(attr);
// 	logs(attr[1]);
// 	logs(attr['second1'][0]);
	
// $('#attr1').bind('onchange', changeAttr2);

</script>


	<div>
		<table class="table_add_url">
			<thead>
				<tr>
					<th>등록날짜</th><th>국가명</th><th>코드</th><th>Active</th><th>동작</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach var="item" items="${locale }">
				<tr>
					<td>${item.time }</td><td class="table_attr"><input type="text" id="name" value="${item.name }" readonly/></td><td class="table_url"><input type="text" id="loc" value="${item.loc }" readonly/></td><td class="table_action"><input type="checkbox" id="active" <c:if test="${item.active ==true}">checked</c:if>/></td>
					<td><input type="button" value="수정" onclick="modify(this)"/></td>
				</tr>
				</c:forEach>
				
				<tr>
					<td></td><td class="table_attr"><input type="text" id="name"/></td><td class="table_url"><input type="text" id="loc"/></td><td class="table_action"><input type="checkbox" id="active"/></td>
					<td><input type="button" value="등록" onclick="insert(this)"/></td>
				</tr>			
			</tbody>
		</table>		
	
	
	</div>
	
	<form method="post" >
		<input type="hidden" name="name" value=""/>
		<input type="hidden" name="loc" value=""/>
		<input type="hidden" name="active" value=""/>
	</form>
	
<script type="text/javascript">



</script>


